package com.ctp.socket.util;

import com.ctp.bean.FormBean;
import com.ctp.controller.manager.TraderManager;
import com.ctp.socket.base.TcpClient;

public class TraderUtil {

	public static String[] openPos(String contr, boolean buyInd, double price,
			int volume, int orderId) {
		StringBuffer sb = new StringBuffer("3;" + contr);

		sb.append(";" + (buyInd ? "1" : "0"));
		sb.append(";" + TraderManager.getIntPrice(price));
		sb.append(";" + volume);
		sb.append(";" + orderId);

		return TcpClient.connect(sb.toString(), PORT);
	}

	public static String[] closePos(String contr, boolean buyInd, double price,
			int volume, int orderId) {
		StringBuffer sb = new StringBuffer("4;" + contr);

		sb.append(";" + (buyInd ? "1" : "0"));
		sb.append(";" + TraderManager.getIntPrice(price));
		sb.append(";" + volume);
		sb.append(";" + orderId);

		return TcpClient.connect(sb.toString(), PORT);
	}

	public static String[] deleteForm(FormBean formBean) {
		StringBuffer sb = new StringBuffer("5");

		sb.append(";" + formBean.getContrName());
		sb.append(";" + formBean.getSeqNum());
		sb.append(";" + formBean.getFormNum());
		sb.append(";" + formBean.getFrontId());
		sb.append(";" + formBean.getSessionId());
		sb.append(";" + formBean.getExchangeId());

		return TcpClient.connect(sb.toString(), PORT);
	}

	private static final int PORT = 8003;

}
